#include<bars.h>
#include<iostream>
Bars::Bars(int uEnd, int dEnd,int x,int c)//都是从上边开始的y坐标
{
    if(c==0)
    {
        imageU.load(":/new/prefix1/flappybird/pipe_down.png");
        imageD.load(":/new/prefix1/flappybird/pipe_up.png");
    }
    if(c==1)
    {
        imageU.load(":/new/prefix1/flappybird/pipe2_down.png");
        imageD.load(":/new/prefix1/flappybird/pipe2_up.png");
    }
    rectU=imageU.rect();
    rectU.moveTo(x,uEnd-rectU.height());
    rectD=imageD.rect();
    rectD.moveTo(x,dEnd);
    space.setHeight(dEnd-uEnd);
    space.setWidth(rectU.width());
    space.moveTo(x,uEnd);
}

Bars::~Bars()
{

}

void Bars::move()
{
    int x=rectU.left()-10;
    int y1=rectU.top();
    int y2=rectD.top();
    rectU.moveTo(x,y1);
    rectD.moveTo(x,y2);
    space.moveTo(x,y2-space.height());

    if(x<-160)
    {
        rectU.moveTo(880,y1);
        rectD.moveTo(880,y2);
    }
}

QRect Bars::getRect(pipeType a)
{
    if(a==0)
           return rectU;
    else
        return rectD;
}

QRect Bars::getSpace()
{
    return  space;
}

QImage &Bars::getImage(pipeType a)
{
    if(a==0)
           return imageU;
    else
        return imageD;
}

void Bars::reset()
{
    int x=rectU.left()+500;
    int y1=rectU.top();
    int y2=rectD.top();
    rectU.moveTo(x,y1);
    rectD.moveTo(x,y2);
}


